<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>主页</title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="author" content="shiva"/>
    <meta name="renderer" content="webkit"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="stylesheet" type="text/css" th:href="@{/fms.css}" media="all">
    <script th:src="@{/static/plugin/vue.global.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/static/plugin/vant/index.css}" media="all">
    <script th:src="@{/static/plugin/vant/vant.min.js}"></script>
    <link rel="icon" th:href="@{/static/images/favicon.ico}" type="image/x-icon"/>
    <link rel="shortcut icon" th:href="@{/static/images/favicon.ico}"/>

    <script th:src="@{/static/plugin/jsencrypt.min.js}"></script>
    <script th:src="@{/static/common.js}"></script>
</head>
<body>
<div id="app">

    <div style="text-align: center">
        <img src="/static/images/material/推婴儿车.png" style="max-width: 60%"/>
    </div>

    <van-grid :column-num="3">
        <van-grid-item icon="coupon" text="标签管理"></van-grid-item>
        <van-grid-item icon="delete" text="回收站" class="grid-green"
                       @click="router('/m/page?type=recovery')"></van-grid-item>
        <van-grid-item icon="umbrella-circle" text="OSS数据初始化" class="grid-green"
                       @click="ossInitConfirm"></van-grid-item>
        <van-grid-item icon="gem" text="OSS差量导入" class="grid-green"
                       @click="differentialImport.show = true"></van-grid-item>
        <van-grid-item icon="weapp-nav" text="OSS配置" class="grid-green"
                       @click="router('/m/page?type=ossParams')"></van-grid-item>
        <van-grid-item icon="descending" text="数据导出"></van-grid-item>
        <van-grid-item icon="ascending" text="数据导入"></van-grid-item>

        <van-grid-item icon="stop-circle" text="修改密码" class="grid-green"
                       @click="router('/m/page?type=password')"></van-grid-item>
        <van-grid-item icon="sort" text="退出登录" class="grid-green" @click="logout"></van-grid-item>
    </van-grid>

    <van-dialog v-model:show="differentialImport.show" title="导入子文件夹"
                @confirm="differentialImportStart()"
                @open="differentialImport.path = ''"
                show-cancel-button>
        <input v-model="differentialImport.path" placeholder="请输入新路径" class="pwd-init-input" style="margin: 30px 30px 10px 30px;width: 80%"/>
        <div style="margin-left: 30px;color: #8f8f8f;font-size: 12px;padding-bottom: 10px">例如：novel/新文件夹/子文件夹/</div>
    </van-dialog>

    <van-floating-bubble icon="wap-home" @click="homepage" style="color: white;background-color: green"/>
</div>
<script>
    Vue.createApp({
        el: '#app',
        data() {
            return {
                requestHeaders: {},
                differentialImport: {
                    show: false,
                    path: '', //新导入的路径
                }
            }
        },
        created() {
            const that = this
            setTimeout(() => {
                that.requestHeaders = commonHeaders()
            }, 200)
        },
        methods: {
            homepage() {
                window.location.href = '/m/index'
            },
            router(page) {
                window.location.href = page
            },
            //退出登录，清楚缓存
            logout() {
                sessionStorage.removeItem('token');
                window.location.href = '/m/page?type=login'
            },
            //确认重置数据，从OSS拉到本地
            ossInitConfirm() {
                const that = this
                vt4.showConfirmDialog({
                    title: '',
                    message: '从OSS初始化数据到本地，会清空本地文件数据和标签关系！！请谨慎操作。',
                }).then(() => {
                    vt4.showConfirmDialog({
                        title: '',
                        message: '再确认一次，数据会清空！！！',
                    }).then(() => {
                        //发请求，获取目录
                        fetch('/api/novel/initFromOss', {
                            method: 'GET',
                            headers: that.requestHeaders,
                        }).then(response => response.json())
                            .then(data => {
                                vt4.showNotify({type: 'success', message: '重置成功'});
                            })
                    }).catch(() => {
                    })
                }).catch(() => {
                })
            },
            //差量导入调用后台
            differentialImportStart() {
                const that = this
                //发请求，获取目录
                fetch('/api/novel/differentialImport?path=' + that.differentialImport.path, {
                    method: 'GET',
                    headers: that.requestHeaders,
                }).then(response => response.json())
                    .then(data => {
                        vt4.showNotify({type: 'success', message: '导入成功！'});
                    })
            }
        }
    }).use(vant).mount("#app");
    const vt4 = vant;
</script>
</body>
</html>